-
Notifications
You must be signed in to change notification settings - Fork 56
Hw2 voskoboinikov #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add addition func
Add substraction func
Add multiplication func
Add division func
Fixed image display
Beautify calculator and Update README.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Отличная работа!
- README понятный, приведены примеры. Только лучше писать README на английском языке.
- Комментарии к коммитам отличные.
- Хорошие, осознанные названия переменных и функций.
- Здорово, что сделали реализацию с while.
Баллы:
За каждую функцию: 1.6 * 5 = 8 баллов
За README 1 + 1 доп. = 2 балла
За наличие всех форков и пулл-реквестов - 1 балл
Дополнительные баллы за pattern matching - 0.2 и 0.1 за while = 0.3 балла.
Итого: 11.3 балла
@@ -0,0 +1,35 @@ | |||
def addition(a, b): | |||
return(a + b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
скобки у return не нужны
return(a + b) | |
return a + b |
@@ -0,0 +1,35 @@ | |||
def addition(a, b): | |||
return(a + b) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
По PEP8 после функции делают 2 пропуска строки
return(a + b) | ||
|
||
def subtraction(a, b): | ||
return(a - b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return(a - b) | |
return a - b |
return(a - b) | ||
|
||
def multiplication(a, b): | ||
return(a * b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return(a * b) | |
return a * b |
return(a * b) | ||
|
||
def division(a, b): | ||
return(a / b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return(a / b) | |
return a / b |
calculator_func_dict = {'-': subtraction, | ||
'*': multiplication, | ||
'+': addition, | ||
'/': division} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
calc_string = input('Enter your expression: ') | ||
|
||
while calc_string != 'exit': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Здорово, что сделали возможность проводить столько вычислений, сколько нужно пользователю👍
calc_string = input('Enter your expression: ') | ||
|
||
while calc_string != 'exit': | ||
command = calc_parser(calc_string)[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно один раз вызвать функцию calc_parser() и потом разом записать в переменные элементы в список, а не трижды ее вызывать. Так работает, но выглядит неоптимально.
Например:
command = calc_parser(calc_string)[1] | |
numb1, command, numb2 = calc_parser(calc_string) |
calc_string = input('Enter your expression: ') | ||
|
||
while calc_string != 'exit': | ||
command = calc_parser(calc_string)[1] | ||
if command in calculator_func_dict: | ||
print(calculator_func_dict[command](calc_parser(calc_string)[0], calc_parser(calc_string)[2])) | ||
else: | ||
print('Seems like an invalid expression. Please, enter valid expression!') | ||
|
||
calc_string = input('Enter your expression: ') | ||
|
||
print('See you next time!') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Этот код тоже можно было обернуть в функцию
calc_string = input('Enter your expression: ') | |
while calc_string != 'exit': | |
command = calc_parser(calc_string)[1] | |
if command in calculator_func_dict: | |
print(calculator_func_dict[command](calc_parser(calc_string)[0], calc_parser(calc_string)[2])) | |
else: | |
print('Seems like an invalid expression. Please, enter valid expression!') | |
calc_string = input('Enter your expression: ') | |
print('See you next time!') | |
def main(): | |
calc_string = input('Enter your expression: ') | |
while calc_string != 'exit': | |
command = calc_parser(calc_string)[1] | |
if command in calculator_func_dict: | |
print(calculator_func_dict[command](calc_parser(calc_string)[0], calc_parser(calc_string)[2])) | |
else: | |
print('Seems like an invalid expression. Please, enter valid expression!') | |
calc_string = input('Enter your expression: ') | |
print('See you next time!') | |
main() | |
Team HW2 on python BI 2023/2024